package com.fruit.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class ValidateUtil {
	
	/**
	 * 手机号验证
	 * @param mobiles
	 * @return
	 */
	public static ResultInfo phone(String phone){
		
		if(StringUtils.isEmpty(phone)){
			return ResultUtil.initResult(ResultInfo.ERROR, "phone_empty", "手机号码不能为空!");
		}
		
		if(StringUtils.length(phone) != 11){
			return ResultUtil.initResult(ResultInfo.ERROR, "phone_error", "手机号码格式错误!");
		}
		
		Pattern p = Pattern.compile("^((14[0-9])|(13[0-9])|(15[^4,\\D])|(17[^4,\\D])|(18[0-9]))\\d{8}$");  
		Matcher m = p.matcher(phone);
		if(!m.matches()){
			return ResultUtil.initResult(ResultInfo.ERROR, "phone_error", "手机号码格式错误!");
		}
		return null;
	}
	
	/**
	 * 验证短信码
	 * @param code
	 * @return
	 * @author admin
	 * @version 2017
	 */
	public static ResultInfo smsCode(String smsCode){
		if(StringUtils.length(smsCode) != 6){
			return ResultUtil.initResult(ResultInfo.ERROR, "smsCode_error", "验证码错误!");
		}
		return null;
	}
	
	
}
